/*
This file is part of vlc-remote.

vlc-remote is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

vlc-remote is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with vlc-remote.  If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 1.1
import com.meego 1.0
import "mediaRemoteFunctions.js" as MediaRemote
import "remoteStatus.js" as RemoteStatus
import "vlcRemote.js" as VlcRemote


PageStackWindow {
    id: appWindow
    property bool firstload: true
    property string server: ""
    property string serverName: "Not Connected"
    property color accentColor: "#f78500"
    property int coverWidth: 480
    property int coverHeight: 450
    property bool autoloadLastConnection: settingsPage.autoloadLastConnection
    property int playerRefreshFocused: settingsPage.playerRefreshFocused
    property int playerRefreshThumbnailed: settingsPage.playerRefreshThumbnailed
    property int playlistRefreshFocused: settingsPage.playlistRefreshFocused
    property int playlistRefreshThumbnailed: settingsPage.playlistRefreshThumbnailed
    property string homeDirectory: "~/"
    property bool shuffle: false
    property bool repeat: false
    property bool playing: false
    property bool paused: false
    property bool playlistDirty: true
    property bool favouritesDirty: true
    property string artist: "Artist"
    property string album: "Album"
    property string title: "Title"
    property string position: "0m00s"
    property string duration: "0m00s"
    property double volume: 0
    property double played:  0
    property alias currentPlaylistItemId: playlistpage.currentItemId

    Component.onCompleted: {
        theme.inverted = true;
        screen.allowedOrientations = Screen.Portrait;
    }
    //onServerChanged: console.debug(server)

    initialPage: playerPage

    PlayerPage{id: playerPage;server: appWindow.server; serverName: appWindow.serverName; }
    BrowsePage{id: browsePage;server: appWindow.server; serverName: appWindow.serverName; }
    FavouritesPage{id: favouritesPage;server: appWindow.server; serverName: appWindow.serverName; }
    PlaylistPage{id: playlistpage;server: appWindow.server; serverName: appWindow.serverName; }
    SettingsPage{id: settingsPage;server: appWindow.server; serverName: appWindow.serverName; }
    RemotesPage{id: remotesPage;onServerChanged: { appWindow.server = server; } onServerNameChanged: {appWindow.serverName = serverName; playlistDirty = true; favouritesDirty = true;} }
    AboutPage{id: aboutPage;}

    PageStackWindowStyle {
        id: vlcRemotePageStyle
        background: "qrc:/qml/gfx/backgrounds/portrait.png"
        portraitBackground: "qrc:/qml/gfx/backgrounds/portrait.png"
        landscapeBackground: "qrc:/qml/gfx/backgrounds/landscape.png"
        backgroundFillMode: Image.Stretch
    }

    platformStyle: vlcRemotePageStyle



    ToolBarLayout {
        id: menuTools
        visible: aboutPage.visible || remotesPage.visible || settingsPage.visible
        ToolIcon {
            width: 80
            id: toolBack
            platformIconId: "toolbar-back";
            anchors.left: parent===undefined ? undefined : parent.left
            onClicked: { myMenu.close(); pageStack.pop(); }
        }
    }

    ToolBarLayout {
        id: commonTools
        visible: playerPage.visible || playlistpage.visible || browsePage.visible
        ButtonRow {
            visible: true
            TabButton {
                id: tabPlayer
                enabled: server != ""
                iconSource: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-content-audio-white.png"
                //text: qsTr("Player")
                onClicked: { onClicked: { myMenu.close(); pageStack.push(playerPage); } }
            }
            TabButton {
                id: tabPlaylist
                enabled: server != ""
                iconSource: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-list-white.png"
                //text: qsTr("Playlist")
                onClicked: { onClicked: { myMenu.close(); pageStack.push(playlistpage); } }
            }
            TabButton {
                id: tabBrowse
                enabled: server != ""
                iconSource: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-directory-white.png"
                //text: qsTr("Browse")
                onClicked: { onClicked: { myMenu.close(); pageStack.push(browsePage); } }
            }
            TabButton {
                id: tabFavourites
                enabled: server != ""
                iconSource: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-favorite-mark-white.png"
                //text: qsTr("Browse")
                onClicked: { onClicked: { myMenu.close(); pageStack.push(favouritesPage); } }
            }

        }
        ToolIcon {
            id: toolPlayer
            platformIconId: "toolbar-content-audio";
            //anchors.centerIn: toolPlaylist.left
            onClicked: { onClicked: { myMenu.close(); pageStack.push(playerPage); } }
            visible: false
        }
        ToolIcon {
            id: toolPlaylist
            platformIconId: "toolbar-list";
            //anchors.right: toolBrowse.left
            onClicked: { onClicked: { myMenu.close(); pageStack.push(playlistpage); } }
            visible: false
        }
        ToolIcon {
            id: toolBrowse
            platformIconId: "toolbar-directory";
            //anchors.right: toolMenu.left
            onClicked: { onClicked: { myMenu.close(); pageStack.push(browsePage); } }
            visible: false
        }
        ToolIcon {
            id: toolMenu
            platformIconId: "toolbar-view-menu";
            anchors.right: parent===undefined ? undefined : parent.right
            onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
            visible: true
        }
    }

    Menu {
        id: myMenu
        visualParent: pageStack
        MenuLayout {
            MenuItem { text: qsTr("Change Remote"); onClicked: { myMenu.close(); pageStack.push(remotesPage); } }
            MenuItem { text: qsTr("Settings"); onClicked: { myMenu.close(); pageStack.push(settingsPage); } }
            MenuItem { text: qsTr("About"); onClicked: { myMenu.close(); pageStack.push(aboutPage); } }
//            MenuItem { text: qsTr("Clear Data"); onClicked: { myMenu.close(); MediaRemote.dropConnectionsTable(); } }
        }
    }

}
